package webServer

import (
	"compress/zlib"
	"encoding/json"
	"fmt"
	"net/http"
	"strconv"

	"public.com/goutil/logUtil"
	"public.com/goutil/zlibUtil"
)

func responseResult(w http.ResponseWriter, responseObj *ResponseObject) {
	b, err := json.Marshal(responseObj)
	if err != nil {
		logUtil.Log(fmt.Sprintf("序列化输出结果%v出错", responseObj), logUtil.Error, true)
		return
	}

	if content, err := zlibUtil.Compress(b, zlib.BestCompression); err == nil {
		w.Header().Add("Content-Length", strconv.Itoa(len(content)))
		w.Write(content)
	} else {
		logUtil.Log(fmt.Sprintf("zlib压缩失败,错误信息为：%s", err), logUtil.Error, true)
	}
}
